package com.exp.bookhouse.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exp.bookhouse.mapper.SysLogMapper;
import com.exp.bookhouse.pojo.SysLog;
import com.exp.bookhouse.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    /**
     * 保存系统日志
     * @param sysLog
     */
    @Override
    public void saveSysLog(SysLog sysLog) {
        sysLogMapper.insert(sysLog);
    }

    /**
     * 查询系统日志
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage<SysLog> querySysLogByPage(Integer page, Integer size) {
        IPage<SysLog> iPage = new Page<>(page,size);
        iPage = sysLogMapper.selectPage(iPage,null);
        return iPage;
    }


    /**
     * 每周一 00:00:00 删除系统日志，或者导出日志
     */
    @Scheduled(cron = "0 0 0 ? * MON")
    public void deleteSysLog(){
        sysLogMapper.delete(null);
    }
}
